window.onload=function (){
    var btn1=document.getElementById("xx1");
    var div1=document.getElementById("xiug");
    var btn2=document.getElementById("xx2");
    var span1=document.getElementById("span1");
    //切换学生名单
    var stuli=document.getElementsByClassName("stuli");
    var stulist=document.getElementById("stulist");
    var astulist=document.getElementById("astulist");
    var ret=document.getElementById("ret");
    //切换学生名单
    var stuli1=document.getElementsByClassName("stuli1");
    var stulist1=document.getElementById("stulist1");
    var astulist1=document.getElementById("astulist1");
    var ret1=document.getElementById("ret1");
    //保存成绩
    var tgrade=document.getElementsByClassName("tgrade");
    var tgrad=document.getElementById("tgrad");
    var tgad=document.getElementById("tgad");
    var span2=document.getElementById("span2");
    btn1.onclick=function (){
        div1.style.display="block";
    }
    for(var i=0;i<tgrade.length;i++){
        tgrade[i].onclick=function (){
            tgad.style.display="block";
        }
    }
    tgrad.onclick=function (){
        tgad.style.display="none";
    }
    span1.onclick=function(){
        div1.style.display="none";
    }
    span2.onclick=function(){
        tgad.style.display="none";
    }
    ret.onclick=function (){
        astulist.style.display="block";
        stulist.style.display="none";
    }
    for(var i=0;i<stuli.length;i++){
        stuli[i].onclick=function (){
            stulist.style.display="block";
            astulist.style.display="none";
        }
    }
    ret1.onclick=function (){
        astulist1.style.display="block";
        stulist1.style.display="none";
    }
    for(var i=0;i<stuli1.length;i++){
        stuli1[i].onclick=function (){
            stulist1.style.display="block";
            astulist1.style.display="none";
        }
    }
}

function getInfo(){
    $.ajax({
        url:"https://dlnu-ljq.cn.utools.club/users/" + 1,
        type:'GET',
        dataType:'JSON',
        contentType:'application/json',
        crossDomain: true,
        asyn:"false",
        success:function(res){
            console.log(res);
            if(res.status != 200){

            } else {
                var gender = "男";
                if(res.data.gender != 1){
                    gender = "女";
                }
                document.getElementById("name").value = res.data.name;
                document.getElementById("sno").value = res.data.sno;
                document.getElementById("gender").value = gender;
                document.getElementById("college").value = res.data.college;
                document.getElementById("regTime").value = res.data.regTime.substring(0, 10).replaceAll('-', '/');
            }
        }
    })
};

function onChangePw(){
    var firstInPw = document.getElementById('firstInPw').value;
    var secInPw = document.getElementById('secInPw').value;
    var lastPw = document.getElementById('lastPw').value;
    var div1=document.getElementById("xiug");
    var sno = document.getElementById("sno").value;
    if(firstInPw != secInPw || (firstInPw.length * secInPw.length * lastPw.length == 0)){
        console.log(firstInPw.length);
        console.log(secInPw.length);
        console.log(lastPw.length);
        alert("输入有误！");
    } else {
        $.ajax({
            url: "https://dlnu-ljq.cn.utools.club/users/login",
            type: "post",
            dataType: "json",
            contentType: 'application/json',
            data: JSON.stringify({
                sno: sno,
                password: lastPw
            }),
            crossDomain: true,
            asyn: "false",
            success: function(res){
                console.log(res);
                if (res.status == 200) {
                    if(firstInPw == secInPw){
                        console.log("发送请求");
                        $.ajax({
                           url:"https://dlnu-ljq.cn.utools.club/users/login",
                            type:'PUT',
                            dataType:'JSON',
                            contentType:'application/json',
                            data:JSON.stringify({
                                userId : 1,
                                sno : sno,
                                password: secInPw
                            }),
                            crossDomain: true,
                            asyn:"false",
                            success:function(res){
                                console.log(res);
                                if(res.status != 200){

                                } else {
                                    document.getElementById('firstInPw').value = "";
                                    document.getElementById('secInPw').value = "";
                                    document.getElementById('lastPw').value = "";
                                }
                                alert("修改成功!");
                                div1.style.display="none";
                            }
                        })
                    } else {
                        alert("输入有误！");
                    }
                } else {
                    alert("输入有误！");
                }
            }
        })
    }
    
} 